let express = require('express')
let router = express.Router()
 
let communitymanmgent = require('./api/communitymanmgent')
let buildingmanagement=require('./api/BuildingManagement')
let HousingManagement=require('./api/houseingmanagement')
let owner=require('./api/owner')
let shop=require('./api/Shopmananement')        //商铺管理
let Garge=require('./api/Gargemanagent')        //车库管理
let Storeroom=require('./api/StoreRoommanagent')    //储藏室管理

const access = require('../controllers/access'); // 引入 access 控制器
const multer = require('multer');
const path = require('path');
 
//社区管理相关，get方法
router.get('/community',communitymanmgent.community)   //查询社区列表
router.get('/communityselect',communitymanmgent.communityselect)    //根据社区查询列表
router.get('/communityadd',communitymanmgent.communityadd)      //添加社区
router.get('/communitypage',communitymanmgent.communitypage)    //社区列表分页器
router.get('/communityedit',communitymanmgent.communityedit)    //社区列表查询编辑
router.get('/communitydel',communitymanmgent.communitydel)    //删除列表某一位
router.get('/communitychange',communitymanmgent.communitychange)    //修改数据

// 楼宇管理相关,get方法
router.get('/buildingmanagement',buildingmanagement.building)
router.get('/buildingmanagementselect',buildingmanagement.buildingselect)   //按条件查询

// 房屋管理相关,get方法
router.get('/houseingmanagement',HousingManagement.houseing)   //查询房屋列表
router.get('/houseingmanagementselect',HousingManagement.houseingselect)   //按条件查询
router.get('/houseingselectowner',HousingManagement.houseingselectowner)    //绑定业主

// 车位管理相关方法,get方法
router.get('/garaglist',Garge.garaglist)   //查询车位列表
// router.get('/garaglistselect',Garge.garaglistselect)    //查询某条数据
router.get('/carportlist',Garge.carportlist)        //查询车库

//业主查询
router.get('/owner',owner.ownerlist)   //查询业主

// 商铺管理相关,get方法
router.get('/shoplist',shop.shoplist)   //查询商铺列表
router.get('/shoplistselect',shop.shoplistselect)   //根据id查询

// 储藏室管理相关, get方法
router.get('/storeroomlist',Storeroom.storeroomlist)
// 储藏室管理相关,post方法
router.post('/storeroomlistuodate',Storeroom.storeroomlistuodate)
router.post('/storeroomlistinsert',Storeroom.storeroomlistinsert)
router.post('/storeroomlisdelate',Storeroom.storeroomlisdelate)
router.post('/storeroomselect',Storeroom.storeroomselect)   //按需查找

// 业主管理
router.get('/ownermanngentlist',owner.ownermanngentlist)


//post方法

// 楼宇管理，post方法
router.post('/buildingmanagementdel',buildingmanagement.buildingdel)    //楼宇删除
router.post('/buildingmanagementadd',buildingmanagement.buildingadd)    //增加楼宇数据
router.post('/buildingmanagementchange',buildingmanagement.buildingchange)    //修改楼宇数据


// 房屋管理,post方法
router.post('/houseingadd',HousingManagement.houseingadd)    //增加楼宇数据
router.post('/houseingchange',HousingManagement.houseingchange)    //修改楼宇数据
// router.post('/houseingchange',HousingManagement.houseingchange)    //修改楼宇数据
router.post('/houseingbingdingowner',HousingManagement.houseingbingdingowner)       //房屋绑定业主
router.post('/housingdel',HousingManagement.housingdel)     //删除某一位数据
router.post('/housinginfomation',HousingManagement.housinginfomation)


// 业主绑定
router.post('/owneradd',owner.owneradd)             //添加业主信息


router.post('/ownerinsert',owner.ownerinsert)       //添加业主
router.post('/ownercontact',owner.ownercontact)     //接触绑定

// 业主管理



//商铺管理,post方法
router.post('/shoplistupdate',shop.shoplistupdate)  //修改商铺数据
router.post('/shoplistinsert',shop.shoplistinsert)  //增加商铺数据
router.post('/shoplistdel',shop.shoplistdel)        //删除商铺数据


// 车库管理相关,post方法
router.post('/garaglistinsert',Garge.garaglistinsert)   //添加车位数据
router.post('/garaglistupdate',Garge.garaglistupdate)   //修改车位数据
router.post('/garaglistdelete',Garge.garaglistdelete)   //删除车位数据某一位

router.post('/carportlistupdate',Garge.carportlistupdate)   //修改车库数据
router.post('/carportlistinsert',Garge.carportlistinsert)   //新增车库数据
router.post('/carportlistdelete',Garge.carportlistdelete)   //删除车库数据
router.post('/parkinglotselect',Garge.parkinglotselect)     //业主id查询车位



// 住户管理
let Household=require('./api/Household')        //住户管理

//get方法
router.get('/householdlist',Household.householdlist)    //查询住户列表
router.post('/householdselect',Household.householdselect)    //按条件查询

// post方法
router.post('/householdinsert',Household.householdinsert)   //添加住户
router.post('/householddelete',Household.householddelete)   //删除住户某一位
router.post('/householdupdate',Household.householdupdate)   //修改用户状态


let { authenticateJWT } = require('./jwt')

// 物业通知信息
let Notice=require('./api/proppertynotice')

router.get('/noticelists',authenticateJWT,Notice.noticelists)
router.post('/noticeinsert',Notice.noticeinsert)
router.post('/noticeupdate',Notice.noticeupdate)
router.post('/noticedelete',Notice.noticedelete)



// 登录token
let Login=require('./api/login')

router.post('/login',Login.login)
router.get('/project',authenticateJWT,Login.project)


// 业主报修
let warranty=require('./api/Warranty')
router.get('/warrantylists',authenticateJWT,warranty.warrantylists)
router.post('/warrantyupdate',authenticateJWT,warranty.warrantyupdate)
router.post('/warrantydelete',authenticateJWT,warranty.warrantydelete)
// 投诉建议
router.get('/complaintlists',authenticateJWT,warranty.complaintlists)   
router.post('/complaintupdate',authenticateJWT,warranty.complaintupdate)
router.post('/complaintdelete',authenticateJWT,warranty.complaintdelete)

// 内部工单
router.get('/workorderlists',authenticateJWT,warranty.workorderlists)
router.post('/workorderdelete',authenticateJWT,warranty.workorderdelete)
router.post('/workorderadd',authenticateJWT,warranty.workorderadd)

// 访客邀请
router.get('/visitorlists',authenticateJWT,warranty.visitorlists)

// 装修申请
router.get('/decorationlists',authenticateJWT,warranty.decorationlists)
router.post('/decorationdeposit',authenticateJWT,warranty.decorationdeposit)
router.post('/decorationdelete',authenticateJWT,warranty.decorationdelete)
router.post('/decorationcheck',authenticateJWT,warranty.decorationcheck)




// 员工管理
let staff=require('./api/staff')
router.get('/stafflists',authenticateJWT,staff.stafflists)
router.post('/stafflistsinsert',authenticateJWT,staff.stafflistsinsert)
router.post('/stafflistssetup',authenticateJWT,staff.stafflistssetup)
router.post('/stafflistsdeactive',authenticateJWT,staff.stafflistsdeactive)
router.post('/stafflistsdel',authenticateJWT,staff.stafflistsdel)
router.post('/stafflistschangeall',authenticateJWT,staff.stafflistschangeall)
router.post('/stafflistssearch',authenticateJWT,staff.stafflistssearch)
router.post('/staffpartersearch',authenticateJWT,staff.staffpartersearch)
router.get('/departmentlists',authenticateJWT,staff.departmentlists)
router.post('/departmentlistsinsert',authenticateJWT,staff.departmentlistsinsert)
router.post('/departmentlistsdel',authenticateJWT,staff.departmentlistsdel)
router.post('/departmentlistsupdate',authenticateJWT,staff.departmentlistsupdate)
router.get('/roleslists',authenticateJWT,staff.roleslists)
router.post('/roleslistsinsert',authenticateJWT,staff.roleslistsinsert)
router.post('/roleslistsdel',authenticateJWT,staff.roleslistsdel)
router.get('/staffpartersort',authenticateJWT,staff.staffpartersort)
router.post('/roleslistsserch',authenticateJWT,staff.roleslistsserch)


// 收费项目
let chargr=require('./api/charge')
router.get('/chargeitems',authenticateJWT,chargr.chargeitems)
router.post('/chargeitemsearch',authenticateJWT,chargr.chargeitemsearch)
router.post('/chargeitemdisable',authenticateJWT,chargr.chargeitemdisable)
router.post('/chargeitemdel',authenticateJWT,chargr.chargeitemdel)
router.post('/chargeiteminsert',authenticateJWT,chargr.chargeiteminsert)
router.get('/meterlists',authenticateJWT,chargr.meterlists)
router.post('/meterlistsinsert',authenticateJWT,chargr.meterlistsinsert)
router.post('/meterlistsdel',authenticateJWT,chargr.meterlistsdel)
router.get('/costlists',authenticateJWT,chargr.costlists)
// 图片上传
// 设置文件存储位置和文件名
const storage = multer.diskStorage({
    destination: (req, file, cb) => {
      cb(null, './uploads');  // 文件存放路径
    },
    filename: (req, file, cb) => {
      cb(null, Date.now() + path.extname(file.originalname));  // 使用时间戳来防止文件重名
    }
  });
  
  // 初始化 multer，设置文件大小限制为 5MB
  const upload = multer({
    storage: storage,
    limits: { fileSize: 5 * 1024 * 1024 }  // 限制最大文件大小为 5MB
  });

  // 路由：处理文件上传
router.post('/access/updated', upload.single('file'), access.updated);

module.exports = router